<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="ProductEntry.aspx.cs" Inherits="ProductEntry" Title="Tackle - Product Entry" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHolder" runat="Server">
    <span style="font-size: 10pt; font-family: Verdana"><strong>Product Entry<br />
    </strong>
        <br />
        <span style="font-size: 8pt">This page allows adding, editing and deleting products
            from the tackle system.<br />
        </span>
        <br />
        <asp:UpdatePanel runat="server" ID="UPGridView" UpdateMode="Conditional" RenderMode="Inline">
            <ContentTemplate>
                <table width="98%" cellpadding="4" cellspacing="0">
                    <tr>
                        <td bgcolor="#e3eaeb" style="border-right: silver 1px ridge; border-top: silver 1px ridge;
                            border-left: silver 1px ridge; border-bottom: silver 1px ridge">
                            <span style="font-size: x-small">Page size:</span><strong> </strong>
                            <asp:DropDownList ID="dlPageSize" runat="server" AutoPostBack="True" Font-Names="Verdana"
                                Font-Size="X-Small" OnSelectedIndexChanged="dlPageSize_SelectedIndexChanged">
                                <asp:ListItem>10</asp:ListItem>
                                <asp:ListItem>25</asp:ListItem>
                                <asp:ListItem>50</asp:ListItem>
                                <asp:ListItem>100</asp:ListItem>
                                <asp:ListItem>All</asp:ListItem>
                            </asp:DropDownList></td>
                    </tr>
                    <tr>
                        <td>
                            <asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="False" CellPadding="4"
                                DataKeyNames="ProductID" DataSourceID="dsProducts" Font-Names="Verdana" Font-Size="X-Small"
                                ForeColor="#333333" GridLines="None" AllowSorting="True" OnRowDeleting="gvProducts_RowDeleting"
                                Width="100%" AllowPaging="True" OnPreRender="gvProducts_PreRender" OnRowDataBound="gvProducts_RowDataBound">
                                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <Columns>
                                    <asp:BoundField DataField="ProductID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                                        SortExpression="ProductID" Visible="False" />
                                    <asp:TemplateField HeaderText="Name" SortExpression="ProductName">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ProductName") %>' Font-Names="Verdana"
                                                Font-Size="X-Small" MaxLength="50" ToolTip="The name of the product" Width="100px"></asp:TextBox><asp:RequiredFieldValidator
                                                    ID="rfv3" runat="server" ControlToValidate="TextBox3" ErrorMessage="*?" ForeColor="LightCoral"
                                                    Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("ProductName") %>' Width="100px"></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Release Date" SortExpression="ReleaseDate">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox2" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("ReleaseDate", "{0:d}") %>' Width="70px"></asp:TextBox><asp:RequiredFieldValidator
                                                    ID="rfv2" runat="server" ControlToValidate="TextBox2" ErrorMessage="*?" ForeColor="LightCoral"
                                                    Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:RangeValidator
                                                        ID="rv1" runat="server" ControlToValidate="TextBox2" ErrorMessage="*#" ForeColor="LightCoral"
                                                        Font-Names="Verdana" Font-Size="X-Small" OnLoad="rv1_Load" ToolTip="This field must contain a valid date"
                                                        Type="Date"></asp:RangeValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("ReleaseDate", "{0:d}") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Product Owner" SortExpression="TnTContact">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("TnTContact") %>' Font-Names="Verdana"
                                                Font-Size="X-Small" MaxLength="50" ToolTip="The Alias user name for the TnT contact for the product"
                                                Width="80px"></asp:TextBox><asp:RequiredFieldValidator ID="rfv5" runat="server" ControlToValidate="TextBox5"
                                                    ErrorMessage="*?" ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small"
                                                    ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label5" runat="server" Text='<%# Bind("TnTContact") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Customer Contact" SortExpression="CustomerContact">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("CustomerContact") %>' Font-Names="Verdana"
                                                Font-Size="X-Small" MaxLength="50" ToolTip="The Alias or Email address of the customer for the product"
                                                Width="80px"></asp:TextBox><asp:RequiredFieldValidator ID="rfv6" runat="server" ControlToValidate="TextBox6"
                                                    ErrorMessage="*?" Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label6" runat="server" Text='<%# Bind("CustomerContact") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Owner Studio" SortExpression="OwnerStudio">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("OwnerStudio") %>' Font-Names="Verdana"
                                                Font-Size="X-Small" MaxLength="50" ToolTip="The studio that owns the product"
                                                Width="60px"></asp:TextBox><asp:RequiredFieldValidator ID="rfv7" runat="server" ControlToValidate="TextBox7"
                                                    ErrorMessage="*?" ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small"
                                                    ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label7" runat="server" Text='<%# Bind("OwnerStudio") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Product CoOwner" SortExpression="TnTCoOwner">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TnTCoOwner") %>' Font-Names="Verdana"
                                                Font-Size="X-Small" MaxLength="50" ToolTip="The Alias user name for the secondary TnT contact for the product"
                                                Width="80px"></asp:TextBox><asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="TextBox1"
                                                    ErrorMessage="*?" Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("TnTCoOwner") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Product Complete" SortExpression="ProductComplete">
                                        <EditItemTemplate>
                                            <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("ProductComplete") %>' />
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("ProductComplete") %>'
                                                Enabled="False" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:CommandField ShowEditButton="True" />
                                    <asp:TemplateField ShowHeader="False">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
                                                Text="Delete" ForeColor="Black" OnClientClick="return confirm('Are you sure you want to delete this record?');"></asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                                <RowStyle BackColor="#E3EAEB" />
                                <EditRowStyle BackColor="#7C6F57" HorizontalAlign="Left" VerticalAlign="Top" />
                                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BackColor="White" />
                            </asp:GridView>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Button ID="btnNewProduct" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                OnClick="btnNewProduct_Click" Text="New Product" />
                            <asp:Label ID="lblCantDelete" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                ForeColor="Red" Text="The product cannot be deleted as associated backlog items exist"
                                Visible="False"></asp:Label></td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
       <asp:SqlDataSource ID="dsProducts" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT tblProducts.ProductID, tblProducts.fScrumTeamProductListID, tblProducts.ProductName, tblProducts.ReleaseDate, tblProducts.TnTContact, tblProducts.CustomerContact, tblProducts.OwnerStudio, tblProducts.TnTCoOwner, tblScrumTeam.ScrumTeamName, tblProducts.ProductComplete FROM tblProducts INNER JOIN tblScrumTeam ON tblProducts.fScrumTeamProductListID = tblScrumTeam.ScrumTeamProductListID WHERE (tblScrumTeam.ScrumTeamID = @ScrumTeamID) ORDER BY tblProducts.ProductName"
            UpdateCommand="UPDATE tblProducts SET ProductName = @ProductName, ReleaseDate = @ReleaseDate, CustomerContact = @CustomerContact, OwnerStudio = @OwnerStudio, TnTContact = @TnTContact, TnTCoOwner = @TnTCoOwner, ProductComplete = @ProductComplete WHERE (ProductID = @original_ProductID)"
            DeleteCommand="DELETE FROM tblProducts WHERE (ProductID = @original_ProductID)">
            <SelectParameters>
                <asp:SessionParameter DefaultValue="" Name="ScrumTeamID" SessionField="ScrumTeamID" />
            </SelectParameters>
        </asp:SqlDataSource>
    </span>
</asp:Content>
